package com.yifi.config;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import cn.hutool.core.util.StrUtil;

public class WebShareFunctions {

	// 数据字典表
	public static List<Record> getDict(String ctype) {
		String sql = "select dict_value as value,dict_label as label,is_default "
				+ " from sys_dict_data where dict_type=?  order by dict_sort ";
		List<Record> list = Db.find(sql, ctype);
		return list;
	}

	/**
	 * 数据字典表
	 * 
	 * @param ctype
	 * @param c_pro
	 * @return
	 */
	public static List<Record> getDict(String ctype, String c_pro) {
		String sql = "select dict_value as value,dict_label as label,is_default "
				+ " from sys_dict_data where dict_type=? and c_pro=? order by dict_sort ";
		List<Record> list = Db.find(sql, ctype, c_pro);
		return list;
	}

	// 班组信息
	public static List<Record> getCdept(String cdept) {
		String sql = "select ccode,cname from mis_org where 1=1 ";

		if (!cdept.equals("all")) {
			sql += " and ccode='" + cdept + "' ";
		}

		sql += " and ilayer='2' ";
		sql += " order by isort";

		List<Record> list = Db.find(sql);
		return list;
	}

	// 班组名称
	public static String getCdeptName(String ccode) {
		String sql = "select cname from mis_org where ccode='" + ccode + "'";
		return Db.queryStr(sql);
	}

	public static String getOption(String ccode) {
		String sql = "select cvalue from sys_option where ccode=?";
		return Db.queryStr(sql, ccode);
	}

	// 获取产权列表
	public static List<Record> getOrgInfo() {
		List<Record> list = getOrgInfo("");
		return list;
	}

	// 获取产权列表
	public static List<Record> getOrgInfo(String orginfo) {
		String sql = "select * from org_info where 1=1 ";
		if (StrUtil.isNotEmpty(orginfo)) {
			sql += " and ccode='" + orginfo + "' ";
		}
		sql += " order by create_time";
		List<Record> list = Db.find(sql);

		if (StrUtil.isEmpty(orginfo)) {
			list.add(0, new Record().set("ccode", "").set("cname", "全部"));
		}
		return list;
	}
}
